<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>015Basic_Shadows</title>
    <link href="../CSS/normalize.min.css"  rel="stylesheet">
    <link href="../CSS/slideout.css"  rel="stylesheet">
    <link href="../CSS/github.css"  rel="stylesheet">
    <link href="../CSS/github.css"  rel="stylesheet">
    <link href="../CSS/font-awesome.min.css"  rel="stylesheet">
    <link href="../CSS/perfect-scrollbar.min.css"  rel="stylesheet">
    <link href="../CSS/main.css"  rel="stylesheet">
</head>
<body>
<!--@@下面是翻译正文@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@-->

<nav id="menu"></nav><nav class="nav-main"><!-- Hamburger menu : displayed only in small screens-->
    <i class="fa fa-bars" id="mobilemenu"></i><!-- this button only shows on mobile version of a "class" page-->
    <div class="banner">
        <div class="menu">
            <div class="do-not-hover" id="home"><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/">Babylon.js | DOCUMENTATION</a></div>
            <div class="item" id="whatsnew"><a style="cursor: help;" href="http://doc.babylonjs.com/whats-new">What's new</a></div>
            <div class="item" id="general"><a style="cursor: help;" href="http://doc.babylonjs.com/generals">General</a></div>
            <div class="item active" id="tutorials"><a style="cursor: help;" href="http://doc.babylonjs.com/tutorials">Tutorials</a></div>
            <div class="item" id="overview"><a style="cursor: help;" href="http://doc.babylonjs.com/overviews">Overviews</a></div>
            <div class="item" id="exporters"><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/exporters">Exporters</a></div>
            <div class="item" id="extensions"><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/extensions">Extensions</a></div>
            <div class="item" id="classes"><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/classes">Classes</a></div>
            <div class="item" id="playground"><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/playground">Playground</a></div></div>
        <div class="more">
            <div class="searchbar">
                <form action="/search" method="get"><input name="q" type="text" placeholder="Search..." value=""><button type="submit"><i class="fa fa-search"></i></button></form></div></div></div></nav>
<div id="wrapper">
    <div class="statics-banner">
        <h1 style="border-image: none; cursor: help;">教程</h1></div>
    <div class="horizontal-separator"></div>
    <div class="static-content">
        <h1 style="border-image: none; cursor: help;">阴影</h1><br>
        <div class="contentTable">
            <div class="tocHeader"><span class="tocTitle" style="border-image: none; cursor: help;"><i class="tocIcon fa fa-book"></i>内容列表</span><span class="tocToggle"><i class="fa fa-arrow-up"></i></span></div>
            <div class="tocContent">
                <ul>
                    <li><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/tutorials/Shadows#introduction">简介</a></li>
                    <li><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/tutorials/Shadows#how-can-i-do-this">怎么做 ?</a></li>
                    <li><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/tutorials/Shadows#filters">过滤</a>
                        <ul>
                            <li><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/tutorials/Shadows#variance-shadow-map">方差阴影图</a></li>
                            <li><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/tutorials/Shadows#poisson-sampling">泊松抽样</a></li>
                            <li><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/tutorials/Shadows#blur-variance-shadow-map">模糊方差阴影图</a></li>
                            <li><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/tutorials/Shadows#examples">例子</a></li></ul></li>
                    <li><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/tutorials/Shadows#about-the-light">关于光</a></li>
                    <li><a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/tutorials/Shadows#next-step">下一步</a></li></ul></div></div>
        <div id="staticContent">
            <h2 style="border-image: none; cursor: help;"><a name="introduction" class="anchor" href="http://doc.babylonjs.com/tutorials/Shadows#introduction"></a>简介</h2>
            <p style="border-image: none; cursor: help;">在这篇教程中，我们将学习怎样在Babylonjs中建立阴影。阴影现在变成动态的了，并且它们根据光来动态形成。</p>
            <p><img alt="Shadows" src="../IMAGE/11-15/15.png"></p>
            <p><em style="border-image: none; cursor: help;">最终效果</em></p>
            <h2 style="border-image: none; cursor: help;"><a name="how-can-i-do-this" class="anchor" href="http://doc.babylonjs.com/tutorials/Shadows#how-can-i-do-this"></a>怎么做 ?</h2>
            <p style="border-image: none; cursor: help;">使用Babylonjs的“阴影形成器”来形成是简单的。这个方法使用一张阴影图：一张你的场景根据光的视点生成的图，就像你能在这里看到的：</p>
            <p><img alt="Shadows2" src="../IMAGE/11-15/15-1.png"></p>
            <p style="border-image: none; cursor: help;">阴影生成器使用的两个参数是：阴影图的大小，以及使用哪个光源来计算阴影图。</p>
<pre><code class="lang-javascript hljs" style="border-image: none; cursor: help;">var shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
</code></pre>
            <p style="border-image: none; cursor: help;">接着，你必须定义渲染哪一个阴影。在这里我们希望渲染圆环的阴影，但是你可以“推入”任何你希望的网格：</p>
<pre><code class="lang-javascript hljs" style="border-image: none; cursor: help;">shadowGenerator.getShadowMap().renderList.push(torus);
</code></pre>
            <p style="border-image: none; cursor: help;">最后，你将必须定义这个阴影在哪里显示。。。通过设置一个网格参数为true</p>
<pre><code class="lang-javascript hljs" style="border-image: none; cursor: help;">ground.receiveShadows = true;
</code></pre>
            <p style="border-image: none; cursor: help;">你可能希望减少由不够精密的阴影图产生的阴影锯齿。为了做到这个，你可以定义“偏斜度”（默认为0.00005）。：</p>
<pre><code class="lang-javascript hljs" style="border-image: none; cursor: help;">shadowGenerator.bias = 0.01;
</code></pre>
            <h2 style="border-image: none; cursor: help;"><a name="filters" class="anchor" href="http://doc.babylonjs.com/tutorials/Shadows#filters"></a>过滤器</h2>
            <p style="border-image: none; cursor: help;">如果你想走的更远，你可以使用阴影过滤.</p>
            <p style="border-image: none; cursor: help;">这里有三种可用的过滤器:</p>
            <h3 style="border-image: none; cursor: help;"><a name="variance-shadow-map" class="anchor" href="http://doc.babylonjs.com/tutorials/Shadows#variance-shadow-map"></a>方差阴影图</h3>
<pre><code class="lang-javascript hljs" style="border-image: none; cursor: help;">shadowGenerator.useVarianceShadowMap = true;
</code></pre>
            <p style="border-image: none; cursor: help;">这个属性默认为<em style="border-image: none; cursor: help;">true</em>, 因为它可以有效的减少阴影的混淆现象。但是如果你希望减少计算时间，请自由的修改它</p>
            <h3 style="border-image: none; cursor: help;"><a name="poisson-sampling" class="anchor" href="http://doc.babylonjs.com/tutorials/Shadows#poisson-sampling"></a>泊松抽样</h3>
<pre><code class="lang-javascript hljs" style="border-image: none; cursor: help;">shadowGenerator.usePoissonSampling = true;
</code></pre>
            <p style="border-image: none; cursor: help;">如果你将这个属性设为<em style="border-image: none; cursor: help;">true</em>, 方差阴影图将会被禁用.这个过滤器使用泊松抽样来柔化阴影。效果会更好，但是速度会更慢。</p>
            <h3 style="border-image: none; cursor: help;"><a name="blur-variance-shadow-map" class="anchor" href="http://doc.babylonjs.com/tutorials/Shadows#blur-variance-shadow-map"></a>模糊方差阴影图</h3>
<pre><code class="lang-javascript hljs" style="border-image: none; cursor: help;">shadowGenerator.useBlurVarianceShadowMap = true;
</code></pre>
            <p style="border-image: none; cursor: help;">这是一个更好的柔化阴影过滤器，但是也同样更慢。它使用模糊方差阴影图。</p>
            <p style="border-image: none; cursor: help;">模糊的质量取决于两个属性:</p>
            <ul>
                <li style="border-image: none; cursor: help;">shadowGenerator.blurScale: 定义缩放等级，在阴影图应用模糊处理前对阴影图进行缩放。默认情况下，这个值是2.</li>
                <li style="border-image: none; cursor: help;">shadowGenerator.blurBoxOffset: 定义用来应用模糊效果的盒子边缘的偏移。默认情况下，这个值是1（意味着这个盒子将在-1和1之间产生九个值用于模糊处理).</li></ul>
            <h3 style="border-image: none; cursor: help;"><a name="examples" class="anchor" href="http://doc.babylonjs.com/tutorials/Shadows#examples"></a>例子</h3>
            <p style="border-image: none; cursor: help;">请在这里找到锥形光源下的方差过滤器的图片:</p>
            <p><img alt="Hard shadows" src="../IMAGE/11-15/hard.jpg"></p>
            <p><em style="border-image: none; cursor: help;">没有过滤器（硬阴影）</em></p>
            <p><img alt="Poisson" src="../IMAGE/11-15/poisson.jpg"></p>
            <p><em style="border-image: none; cursor: help;">泊松抽样</em></p>
            <p><img alt="VSM" src="../IMAGE/11-15/vsm.jpg"></p>
            <p><em style="border-image: none; cursor: help;">方差阴影图</em></p>
            <p><img alt="BlurVSM" src="../IMAGE/11-15/blurVSM.jpg"></p>
            <p><em style="border-image: none; cursor: help;">模糊方差阴影图</em></p>
            <h2 style="border-image: none; cursor: help;"><a name="about-the-light" class="anchor" href="http://doc.babylonjs.com/tutorials/Shadows#about-the-light"></a>关于光</h2>
            <p style="border-image: none; cursor: help;">请记住一个阴影产生器只能配合一个光源使用。如果你希望通过另一个光源产生阴影，那么你需要建立另一个阴影产生器。</p>
            <p style="border-image: none; cursor: help;">只有点、方向和锥形光源可以产生阴影:</p>
<pre><code style="border-image: none; cursor: help;" class="lang-javascript hljs">var light = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(-1, -2, -1), scene);
</code></pre>
            <p style="border-image: none; cursor: help;">点光源使用“立方贴图”渲染，所以请小心使用它们，因为它们可能导致性能问题。</p>
            <p style="border-image: none; cursor: help;">锥形光源使用透视投影，方向光源使用正交投影。这两种投影都被自动估算消耗，让你获得尽可能好的阴影图。</p>
            <p style="border-image: none; cursor: help;">对于方向光源，你可以控制投影窗口的尺寸通过修改<code style="border-image: none; cursor: help;">light.shadowOrthoScale</code> (默认为0.1意味着这个投影窗口从理想尺寸扩展了百分之十).</p>
            <p style="border-image: none; cursor: help;">光源的位置，像你推入渲染列表的网格位置一样，决定着阴影将出现在哪里。</p>
            <p style="border-image: none; cursor: help;">现在你可能希望访问<a href="http://babylonjs-playground.azurewebsites.net/?15"><strong style="border-image: none; cursor: help;">playground场景</strong></a>为这一篇教程.</p>
            <p style="border-image: none; cursor: help;">你也可以访问<a style="border-image: none; cursor: help;" href="http://www.babylonjs-playground.com/#LYCSQ#12">点光源阴影图playground场景</a> - <i class="fa fa-eye" onclick="createIframe('LYCSQ#12', this)"></i><br>
            <div class="iframeContainer"></div><br>
            <p></p>
            <h2 style="border-image: none; cursor: help;"><a name="next-step" class="anchor" href="http://doc.babylonjs.com/tutorials/Shadows#next-step"></a>下一步</h2>
            <p style="border-image: none; cursor: help;">既然你已经是一个关于Babylonjs的真正的专家，可能已经是时候深入代码处理复杂的着色器、网格或者纹理。我们的<a style="border-image: none; cursor: help;" href="http://doc.babylonjs.com/">维基主页</a>是你取得很多高级话题的入口。你也可以参加这个项目通过访问我们的Github页面：<a style="border-image: none; cursor: help;" href="https://github.com/BabylonJS/Babylon.js">https://github.com/BabylonJS/Babylon.js</a>或者你也可以参加我们非常活跃的论坛： <a style="border-image: none; cursor: help;" href="http://www.html5gamedevs.com/forum/16-babylonjs">http://www.html5gamedevs.com/forum/16-babylonjs</a>.在那里见.</p></div></div>
</div>

<!--@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@-->

<footer class="footer"><div class="footer-item"><a style="border-image: none; cursor: help;" href="http://www.html5gamedevs.com/forum/16-babylonjs" target="_blank"><i class="fa fa-html5"></i>    Forum</a></div><div class="footer-item"><a style="border-image: none; cursor: help;" href="https://github.com/BabylonJS/Babylon.js" target="_blank"><i class="fa fa-github"></i>    Github</a></div><div class="footer-item"><a style="border-image: none; cursor: help;" href="https://github.com/BabylonJS/Documentation" target="_blank"><i class="fa fa-code-fork"></i>    Contribute</a></div></footer>
<div style="position: static; width: 0px; height: 0px; border: none; padding: 0px; margin: 0px;"><div id="trans-tooltip"><div id="tip-left-top" style="background: url(chrome-extension://ikkbfngojljohpekonpldkamedehakni/imgs/map/tip-left-top.png);"></div><div id="tip-top" style="background: url(chrome-extension://ikkbfngojljohpekonpldkamedehakni/imgs/map/tip-top.png) repeat-x;"></div><div id="tip-right-top" style="background: url(chrome-extension://ikkbfngojljohpekonpldkamedehakni/imgs/map/tip-right-top.png);"></div><div id="tip-right" style="background: url(chrome-extension://ikkbfngojljohpekonpldkamedehakni/imgs/map/tip-right.png) repeat-y;"></div><div id="tip-right-bottom" style="background: url(chrome-extension://ikkbfngojljohpekonpldkamedehakni/imgs/map/tip-right-bottom.png);"></div><div id="tip-bottom" style="background: url(chrome-extension://ikkbfngojljohpekonpldkamedehakni/imgs/map/tip-bottom.png) repeat-x;"></div><div id="tip-left-bottom" style="background: url(chrome-extension://ikkbfngojljohpekonpldkamedehakni/imgs/map/tip-left-bottom.png);"></div><div id="tip-left" style="background: url(chrome-extension://ikkbfngojljohpekonpldkamedehakni/imgs/map/tip-left.png);"></div><div id="trans-content"></div></div><div id="tip-arrow-bottom" style="background: url(chrome-extension://ikkbfngojljohpekonpldkamedehakni/imgs/map/tip-arrow-bottom.png);"></div><div id="tip-arrow-top" style="background: url(chrome-extension://ikkbfngojljohpekonpldkamedehakni/imgs/map/tip-arrow-top.png);"></div></div>

<!--@@下面是工具脚本@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@-->

<div id="div_hidden" style="display: none">
    <div id="div_mod1">
        <div class="div_inmod1" style="width: 100%;height: 100%;margin: 0px;border: 1px solid;padding: 0px;float: left;line-height: 20px" >
            <button onclick="ExportHtml()" style="margin-left: auto;margin-right: auto;float: left;position: relative;left: 10px">导出网页</button>
        </div>
    </div>
    <div id="div_mod2">
        <div class="div_inmod2" style="width: 100%;height: 100%;margin: 0px;border: 1px solid;padding: 0px;float: left;line-height: 20px">
            <div class="div_inmod_head" style="width: 100%;height: 20px;background-color: #E0ECFF;margin:0;border: 0;padding:0;border-bottom: 1px solid">
                <BUTTON title="点击关闭对话框" style='float:right;aposition:static; width: 14px;height: 14px; margin: 0;margin-top: 2px;margin-right:2px;padding: 0;background: url("") no-repeat;border: 0px;vertical-align:top' onclick="DeleteWindow();" type=submit></BUTTON>
                <BUTTON title="点击确定修改" style='float:right;aposition:static; width: 14px;height: 14px; margin: 0;margin-top: 2px;margin-right:2px;padding: 0;background: url("") no-repeat;border: 0px;vertical-align:top' onclick="ChangeValue();DeleteWindow();" type=submit></BUTTON>
                <BUTTON title="点击恢复上一历史状态" style='float:right;aposition:static; width: 14px;height: 14px; margin: 0;margin-top: 2px;margin-right:2px;padding: 0;background: url("") no-repeat;border: 0px;vertical-align:top' onclick="ReloadValue();DeleteWindow();" type=submit></BUTTON>
            </div>
            <textarea class="div_inmod2_content" style="width: 100%;height: 98px;overflow-x: hidden;margin:0;border: 0;padding:0" onchange=""></textarea>
        </div>
    </div>
</div>
<script src="../JS/MYLIB/MIN/Events.min.js"></script>
<script src="../JS/MYLIB/MIN/FileText.min.js"></script>
<script src="../JS/MYLIB/MIN/View.min.js"></script>
<script>
    var bbl_current_obj;
    var bbl_style_temp;
    var bbl_int_count2=0;
    var bbl_arr_history=[];
    window.onload=function()
    {
        delete_div("div_ExportHtml");
        if(true)
            return;
        Open_div("","div_ExportHtml",100,80,0,0);
        var div_ExportHtml=document.getElementById("div_ExportHtml");
        div_ExportHtml.innerHTML=document.getElementById("div_mod1").innerHTML;
        div_ExportHtml.style.position="fixed";
        div_ExportHtml.style.right="0px";
        div_ExportHtml.style.top="300px";
        //div_ExportHtml.style.float="right";
        var int_count=0;//为每一个可调整标签设置不同的tid属性
        var arr_tags=["p","a","span","h1","h2","h3","h4","h5","li","td","th","code","strong","em"];
        var leng=arr_tags.length;
        for(var i=0;i<leng;i++)//对于每一种标签
        {
            var objs=document.getElementsByTagName(arr_tags[i]);
            var leng2=objs.length;
            for(var j=0;j<leng2;j++)//对于每一个标签
            {
                var children=objs[j].childNodes;
                var leng3=children.length;
                for(var k=0;k<leng3;k++)//寻找文本节点
                {
                    if(children[k].nodeName=="#text"&&children[k].textContent.Trim().length>2)
                    {
                        objs[j].tid="tid"+int_count;
                        objs[j].style.cursor="help";
                        objs[j].onmouseover=function()
                        {
                            bbl_style_temp=this.style.border;
                            this.style.border="2px solid rgb(59, 203, 249)";
                            bbl_current_obj=objs[j];
                        }
                        objs[j].onmouseout=function()
                        {
                            this.style.border=bbl_style_temp;
                        }
                        objs[j].onclick=function(){
                            var evt=evt||window.event;
                            cancelEvent(evt);
                            cancelPropagation(evt);
                            //alert(this.textContent);
                            var arr_child=this.childNodes;
                            var leng4=arr_child.length;
                            //首先删除所有已经存在的对话框
                            for(var l=0;l<bbl_int_count2;l++)
                            {
                                delete_div("div_inmod2_"+l);
                            }
                            bbl_int_count2=0;
                            for(var l=0;l<leng4;l++)//对于其中的每一个文本节点，弹出修改对话框
                            {
                                if(arr_child[l].nodeName=="#text"&&arr_child[l].textContent.Trim().length>2)
                                {
                                    Open_div(this,"div_inmod2_"+bbl_int_count2,240,120,0+bbl_int_count2*250,0);
                                    var div_inmod2=document.getElementById("div_inmod2_"+bbl_int_count2);//取出新添加的元素
                                    div_inmod2.ttid=this.getAttribute("tid")?this.getAttribute("tid"):this.tid;//把被选择标签的全局标记交给弹出框
                                    div_inmod2.tobj=this;
                                    div_inmod2.textnum=l;//在文本框中记录，这个文本框对应的是标签的第几个子节点
                                    div_inmod2.innerHTML=document.getElementById("div_mod2").innerHTML;
                                    con_getElementsByClassName("div_inmod2_content",div_inmod2)[0].innerHTML=arr_child[l].textContent;//填入原有值，考虑标签嵌套问题//#text型标签没有innerhtml属性！！
                                    bbl_int_count2++;//记下有多少个，后面删除所有对话框时使用
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
    function DeleteWindow()
    {//只删除掉点击关闭的这一个标签
        var evt=evt||window.event;
        cancelPropagation(evt);
        var obj=evt.currentTarget?evt.currentTarget:evt.srcElement;
        var str_id=obj.parentNode.parentNode.parentNode.id;
        delete_div(str_id);
    }
    //写入修改后的标签值，并写入日志
    function ChangeValue()
    {
        var evt=evt||window.event;
        cancelPropagation(evt);
        var obj=evt.currentTarget?evt.currentTarget:evt.srcElement;
        //document.getElementsByTagName()
        var div_inmod2=obj.parentNode.parentNode.parentNode;
        var obj_text=obj.parentNode.parentNode.getElementsByTagName("textarea")[0];//输入的文本框
        if(obj_text.innerHTML.trim().length<1)
        {
            alert("修改后的文本过短");
        }
        else {
            var tobj = div_inmod2.getAttribute("tobj") ? div_inmod2.getAttribute("tobj") : div_inmod2.tobj;//取得该输入框对应的标签
            var ttid = div_inmod2.getAttribute("tid") ? div_inmod2.getAttribute("tid") : div_inmod2.tid;//
            var textnum = div_inmod2.getAttribute("textnum") ? div_inmod2.getAttribute("textnum") : div_inmod2.textnum;
            //写日志
            var arr_temp = [];
            arr_temp.push(ttid + "&" + textnum);
            arr_temp.push(tobj.childNodes[textnum].textContent);
            bbl_arr_history.push(arr_temp);
            //改值
            tobj.childNodes[textnum].textContent = obj_text.innerHTML;
        }
    }
    //根据日志恢复标签内容
    function ReloadValue()
    {
        var evt=evt||window.event;
        cancelPropagation(evt);
        var obj=evt.currentTarget?evt.currentTarget:evt.srcElement;
        var div_inmod2=obj.parentNode.parentNode.parentNode;
        var tobj=div_inmod2.getAttribute("tobj")?div_inmod2.getAttribute("tobj"):div_inmod2.tobj;//取得该输入框对应的标签
        var ttid=div_inmod2.getAttribute("tid")?div_inmod2.getAttribute("tid"):div_inmod2.tid;//
        var textnum=div_inmod2.getAttribute("textnum")?div_inmod2.getAttribute("textnum"):div_inmod2.textnum;


        var flag=0;//0表示没有找到，对应的日志记录
        var leng=bbl_arr_history.length;
        for(var i=leng-1;i>=0;i--)
        {
            var str=ttid+"&"+textnum;
            if(bbl_arr_history[i][0]==str)//找到新的这一条
            {
                tobj.childNodes[textnum].textContent=bbl_arr_history[i][1];
                bbl_arr_history.splice(i,1);//将日志里的这一条删除
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            alert("没有日志记录！");
        }
    }
    //以html格式导出网页
    function ExportHtml()
    {
        DownloadText(MakeDateStr()+document.title,("<!DOCTYPE html><html>"+document.getElementsByTagName("html")[0].innerHTML+"</html>"));
    }
</script>
</body>
</html>